home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / cacheControl.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  4.5 KB  |  161 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. // Alias|Wavefront Script File
  19. // MODIFY THIS AT YOUR OWN RISK
  20. //
  21.  
  22. proc int dynSettingsInList(string $list[], string $name)
  23. //
  24. // Return whether $name is in $list.
  25. //
  26. {
  27.     int $inList = 0;
  28.     for ($i = 0; $i < size($list); $i++)
  29.     {
  30.         if ($name == $list[$i])
  31.         {
  32.             $inList = 1;
  33.             break;
  34.         }
  35.     }
  36.     return $inList;
  37. }
  38.  
  39. global proc cacheControl( int $flag )
  40. //
  41. // Enable the cache for all the selected dynamic objects.
  42. {
  43.  
  44.     // What's selected is probably a transform, so we probably have to find the particle,
  45.     // rigid body shapes in the transforms.
  46.     //
  47.     // Get selected particles and rigid bodies if there are any.
  48.     //
  49.     string $selectedParticles[] = `ls -sl -type particle`;
  50.     string $selectedRigidBodies[] = `ls -sl -type rigidBody`;
  51.     string $selectedTransforms[] = `ls -sl -transforms`;
  52.  
  53.     // Get the particle shapes from all selected transforms that own
  54.     // particle shapes. 
  55.     //
  56.     for ($i = 0; $i < size($selectedTransforms); $i++)
  57.     {
  58.         string $kidShapes[] = `listRelatives -s $selectedTransforms[$i]`;
  59.         string $particleKids[] = `ls -type particle $kidShapes`;
  60.         int $particleCount = size($selectedParticles);
  61.         for ($j = 0; $j < size($particleKids); $j++)
  62.         {
  63.             if (!dynSettingsInList($selectedParticles, $particleKids[$j]))
  64.             {
  65.                 $selectedParticles[$particleCount] = $particleKids[$j];
  66.                 $particleCount++;
  67.             }
  68.         }
  69.     }
  70.  
  71.     // Get the rigid body shapes from all selected transforms that own
  72.     // rigid body shapes. 
  73.     //
  74.     for ($i = 0; $i < size($selectedTransforms); $i++)
  75.     {
  76.         string $kidShapes[] = `listRelatives -s $selectedTransforms[$i]`;
  77.         string $rigidBodyKids[] = `ls -type rigidBody $kidShapes`;
  78.         int $rigidCount = size($selectedRigidBodies);
  79.         for ($j = 0; $j < size($rigidBodyKids); $j++)
  80.         {
  81.             if (!dynSettingsInList($selectedRigidBodies, $rigidBodyKids[$j]))
  82.             {
  83.                 $selectedRigidBodies[$rigidCount] = $rigidBodyKids[$j];
  84.                 $rigidCount++;
  85.             }
  86.         }
  87.     }
  88.  
  89.     // Collect the list of unique rigid solvers related to the selected rigid
  90.     // bodies and set the solver names in one string for the feedback line,
  91.     // because the caching is done by the solver, rather than the rigid body.
  92.     //
  93.     string $rigidSolvers[];
  94.     string $rigidSolver;
  95.     string $rigidSolverNames;
  96.     int $solverCount = 0;
  97.  
  98.     for ($i = 0; $i < size($selectedRigidBodies); $i++)
  99.     {
  100.         $rigidSolver = `rigidBody -q -solver $selectedRigidBodies[$i]`;
  101.         if (!dynSettingsInList($rigidSolvers, $rigidSolver))
  102.         {
  103.             $rigidSolvers[$solverCount] = $rigidSolver;
  104.             $rigidSolverNames = $rigidSolverNames + " " + $rigidSolver;
  105.             $solverCount++;
  106.         }
  107.     }
  108.  
  109.     // Now set cache for each particle.
  110.     //
  111.     int $particleCount = size($selectedParticles);
  112.  
  113.     string $cmd = "particle -e -cache " + $flag;
  114.     string $particleNames;
  115.     for ($i = 0; $i < $particleCount; $i++)
  116.     {
  117.         $cmd = "particle -e -cache " + $flag + " " + $selectedParticles[$i];
  118.         $particleNames = $particleNames + " " + $selectedParticles[$i];
  119.         evalEcho $cmd;
  120.  
  121.     }
  122.  
  123.     // Give the user feedback.
  124.     //
  125.     if ($particleCount > 0)
  126.     {
  127.         if ( $flag )
  128.         {
  129.             print ( "// Result: Cache enabled for " + $particleNames + ".\n" );
  130.         }
  131.         else
  132.         {
  133.             print ( "// Result: Cache disabled for " + $particleNames + ".\n" );
  134.         }
  135.     }
  136.  
  137.  
  138.     // Now set cache for each rigid solver.
  139.     //
  140.     $solverCount = size($rigidSolvers);
  141.     for ($i = 0; $i < $solverCount; $i++)
  142.     {
  143.         $cmd = "rigidSolver -e -cacheData " + $flag + " " + $rigidSolvers[$i];
  144.         evalEcho $cmd;
  145.     }
  146.  
  147.     // Give the user feedback.
  148.     //
  149.     if ($solverCount > 0)
  150.     {
  151.         if ( $flag )
  152.         {
  153.             print ( "// Result: Cache enabled for all rigid bodies of: " + $rigidSolverNames + ".\n" );
  154.         }
  155.         else
  156.         {
  157.             print ( "// Result: Cache disabled for all rigid bodies of: " + $rigidSolverNames + ".\n" );
  158.         }
  159.     }
  160. }
  161.